<template>
	<view>
		<uni-swiper-dot class="uni-swiper-dot-box" :info="info" :current="current" :mode="mode" field="content">
			<swiper class="swiper-box" @change="change" :current="swiperDotIndex" :autoplay="autoplay"
				:interval="interval" :circular="true" :duration="duration">
				<swiper-item v-for="(item, index) in info" :key="index">
					<view class="swiper-item">
						<image :src='item.url' mode="aspectFill" :draggable="false"></image>
					</view>
				</swiper-item>
			</swiper>
		</uni-swiper-dot>
	</view>
</template>

<script>
	import SqlLite from '../utils/sqlite/sqlLite.js'
	export default {
		data() {
			return {
				info: [{
						url: '../static/swiper/1.jpg'
					},
					{
						url: '../static/swiper/2.jpg'
					},
					{
						url: '../static/swiper/3.jpg'
					},
					{
						url: '../static/swiper/4.jpg'
					},
					{
						url: '../static/swiper/5.jpg'
					}
				],

				modeIndex: -1,
				styleIndex: -1,
				current: 0,
				autoplay: true, // 开启自动播放 
				interval: 3000, // 自动切换时间间隔（毫秒）
				duration: 500, // 滑动动画时长（毫秒）
				mode: 'default',
				dotsStyles: {},
				swiperDotIndex: 0,
				dbName: 'media',
				dbPath: '_doc/' + 'media.db',
				tableName: "banner",
				chatText1: [{
						id: 38,
						fromId: '123',
						toId: '321',
						content: '你好!',
						flag: 1
					},
					{
						id: 39,
						fromId: '123',
						toId: '321',
						content: '你好!',
						flag: 1
					}
				]
			}
		},
		async mounted() {
			let isOpen = SqlLite.isOpen(this.dbName, this.dbPath)
			console.log('监听数据库是否打开', isOpen);
			//数据库没有打开
			if (!isOpen) {
				//打开数据库
				SqlLite.openSqlite()
			}

			// 2. 安全检查表存在性 
			const tableExists = await SqlLite.safeIsTable(this.dbPath, this.tableName,this.dbName);
			console.log("表是否存在",tableExists);
			if (tableExists) {
				let sql =
					'CREATE TABLE IF NOT EXISTS banner (list INTEGER PRIMARY KEY AUTOINCREMENT,id TEXT UNIQUE,content TEXT NOT NULL,fromId TEXT,toId TEXT,flag INTEGER DEFAULT 0,name TEXT,gender TEXT,avatar TEXT)'
				SqlLite.addTable(this.dbName,sql)
				//添加数据
				for (let i = 0; i < this.chatText1.length; i++) {
					let sql = `INSERT OR REPLACE INTO ${this.tableName}  (id, content, fromId, toId, flag) 
               VALUES ('${this.chatText1[i].id}',  '${this.chatText1[i].content}',  
                       '${this.chatText1[i].fromId}',  '${this.chatText1[i].toId}',  
                        ${this.chatText1[i].flag})`;
					SqlLite.addTableData(this.dbName, sql)
				}
				let list = await SqlLite.pullSQL(this.tableName, 0)
				console.log("表的数据", list);
			}
		},
		methods: {

			change(e) {
				this.current = e.detail.current;
			}
		},
		onLoad: function() {}
	}
</script>

<style>
	.swiper-box {
		height: 100vh;
	}

	.swiper-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;
		color: #fff;
		height: 100vh;
		line-height: 100vh;
	}
</style>